package com.zretc.controller;

import com.github.pagehelper.PageInfo;
import com.zretc.entity.Movie;
import com.zretc.service.MovieBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;


@RequestMapping("/movieManage")
@Controller
public class MovieBackController {

    @Autowired
    private MovieBackService movieBackService;

    @ResponseBody
    @RequestMapping("/comeMovie")
    public PageInfo<Movie> getMovie(@RequestParam(value = "pageNum") String pageNum,
                                        @RequestParam(value = "pageSize") String pageSize,
                                        @RequestParam(value = "adminId") String adminId){

        // 2.调用业务层
        Map<String, String> map = new HashMap<>();
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);
        map.put("adminId",adminId);

        // 调用方法
        PageInfo<Movie> movieByAdminId = movieBackService.getMovieByAdminId(map);

        return movieByAdminId;

    }

    @ResponseBody
    @RequestMapping("/comeMovieList")
    public PageInfo<Movie> getMovieList(@RequestParam(value = "pageNum") String pageNum,
                                        @RequestParam(value = "pageSize") String pageSize,
                                        @RequestParam(value = "movieName") String movieName,
                                        @RequestParam(value = "adminId") String adminId){

        // 2.调用业务层
        Map<String, String> map = new HashMap<>();
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);
        map.put("movieName",movieName);
        map.put("adminId",adminId);

        // 调用方法
        PageInfo<Movie> movieList = movieBackService.getMovieByAdminIdAndMovieName(map);

        return movieList;

    }

    // @ResponseBody
    @RequestMapping("/downMovie")
    public String setdown(@RequestParam(value = "adminId") String adminId,
                          @RequestParam(value = "movieId") String movieId){

        boolean deleteMovie = movieBackService.deleteMovie(movieId, adminId);

        if(deleteMovie == true){
            return "forward:comeMovieList";
        }else{
            return "forward:skipCome";
        }

    }

    @RequestMapping("/skipCome")
    public String skip(){
        return "redirect:../back/movie_back.jsp";
    }
}
